package com.rwind.dynamic.datasource;

import java.util.Date;
import java.util.List;

import javax.annotation.PostConstruct;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

@Component
public class MyBeanPostProcessor implements BeanFactoryPostProcessor,ApplicationRunner {

	 
	private ConfigurableListableBeanFactory beanFactory;
 

	@Override
	public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
		 this.beanFactory = beanFactory; 
		
	}
 


	@Override
	public void run(ApplicationArguments args) throws Exception {
		/*
		PayInfoDictPo query = new PayInfoDictPo();
		query.setCodeType("ACP_DIST_CONF");
		PayinfoDictMapper payinfoDictMapper = beanFactory.getBean(PayinfoDictMapper.class); 
		List<PayInfoDictPo> list = payinfoDictMapper.selectPayInfoDict(query);
		*/
		String beanClass = "com.huoli.pasettle.tempbean.DemoBean";

		BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(beanClass);
		builder.addPropertyValue("name", "rwind");
		builder.addPropertyValue("day", new Date());
		DefaultListableBeanFactory defaultBeanFactory = (DefaultListableBeanFactory) beanFactory;
		defaultBeanFactory.registerBeanDefinition("demoBean", builder.getBeanDefinition());
		
	}

}